package com.service.purchase;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.common.DateUtils;
import com.common.StringUtils;
import com.dao.purchase.PurchaseMapper;

import ch.qos.logback.classic.db.names.ColumnName;

@Service
public class CommonService {

	static final Logger logger = LoggerFactory.getLogger(CommonService.class);

	@Autowired
	PurchaseMapper purchaseMapper;

	public String createCode(String tableName, String colName) {
		String codeString = "";
		String count = purchaseMapper.getTableLast(tableName, colName) + 1;

		int countLast = 1;
		if (count.equals("null1")) {

		} else if (StringUtils.isNotNull(count)) {
			String tempString = count.substring(11, 16);
			countLast = Integer.parseInt(tempString) + 1;
		}

		codeString = DateUtils.getCurrentDate() + "-" + StringUtils.lpad(countLast + "", 5, "0");
		return codeString;

	}

	public String createCodeSap(String tableName, String colName) {
		String codeString = "";
		String count = purchaseMapper.getOrderLast(tableName, colName) + 1;

		int countLast = 1;
		if (count.equals("null1")) {

		} else if (StringUtils.isNotNull(count)) {
			String tempString = count.substring(11, 16);
			countLast = Integer.parseInt(tempString) + 1;
		}

		codeString = DateUtils.getCurrentDate() + "-" + StringUtils.lpad(countLast + "", 5, "0");
		return codeString;

	}

}
